<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>订单详情</title>
<%@ include file="/WEB-INF/jsp/public/commons.jspf"%>

<script type="text/javascript">
	//获取订单类型
	var dealType = '${dealType}';
	var marketId = '<s:property value="market.id"/>';
	var bool = true;
	//为每个goodsnum文本框添加事件 验证
	$(function() {
		$('.editnum').hide();
		$('.shownum').click(function() {
			bool = false;
			$(this).hide();

			var id = $(this).attr("id");
			var editnumid = "edit" + id;
			$('#' + editnumid).show();
			$('#' + editnumid).blur(function() {
				var num = $(this).val();
				inputverification(id, num, function(msg) {
					if (msg == "true") {
						updateGoodsnum(id, num);
						$('#err' + id).html("");
						$('#' + id).text(num);
						$('#' + id).show();
						$('#' + editnumid).hide();
						bool = true;
					} else {
						bool = false;
						$('#err' + id).html(msg);
					}
				});
			});
		});
	});
	//更新子项数量
	function updateGoodsnum(id, num) {
		$.ajax({
			type : "POST",
			url : "storage_updateGoodsnum.do",
			data : "&dealType=" + dealType + "&goodsIdStr=" + id + "&goodsnum="
					+ num,
			success : function(msg) {
				bool = true;
			}
		});
	}
	//验证每项输入的方法()
	function inputverification(id, num, fun) {
		//验证正整数
		if (!(/^(\+|-)?\d+$/.test(num))) {
			$('#err' + id).html("请输入正整数");
			;
			return;
		}
		//验证库存数
		$.ajax({
			type : "POST",
			url : "storage_goodsnumValidation.do",
			data : "&dealType=" + dealType + "&goodsIdStr=" + id + "&goodsnum="
					+ num + "&marketId=" + marketId,
			dataType : "text",
			success : fun
		});
	}
	//删除当前订单子项
	function todelItem(goodsid) {
		if (confirm("确定删除吗？")) {
			$.ajax({
				type : "POST",
				url : "storage_delItem.do",
				data : "&dealType=" + dealType + "&goodsIdStr=" + goodsid,
				success : function(msg) {
					location.href = "storage_toOrder.do?dealType=" + dealType;
				}
			});
		}
	}
	//清除当前类型订单
	function toClean() {
		if (confirm("确定清除吗？")) {
			$.ajax({
				type : "POST",
				url : "storage_Cleanorder.do",
				data : "&dealType=" + dealType,
				success : function(msg) {
					location.href = "storage_toOrder.do?dealType=" + dealType;
				}
			});
		}
	}
	//保存当前类型的订单
	function toSave() {
		if (bool) {
			$.ajax({
				type : "POST",
				url : "storage_Saveorder.do",
				data : "&dealType=" + dealType,
				success : function(msg) {
					location.href = "order_list.do";
					//alert('保存成功');
				}
			});
		}
	}
</script>

</head>
<body>
	<div id="Title_bar">
		<div id="Title_bar_Head">
			<div id="Title_Head"></div>
			<div id="Title">
				<!--页面标题-->
				<img border="0" width="13" height="13"
					src="${pageContext.request.contextPath}/style/images/title_arrow.gif" />
				<s:if test="dealType == 1">上架明细车</s:if>
				<s:if test="dealType == 2">下架明细车</s:if>
				<s:if test="dealType == 3">进货明细车</s:if>
				<s:if test="dealType == 4">退货明细车</s:if>
			</div>
			<div id="Title_End"></div>
		</div>
	</div>
	<div id="QueryArea">
		<div style="height: 50px">
			<table>
				<tr>
					<td>订单对象：</td>
					<td><s:property value="market.name" /> <s:property
							value="supplier.name" /></td>
					<td>订单时间：</td>
					<td><s:property value="date" />
					</td>
					<td>订单总额：</td>
					<td><s:property value="orderzonge" />
					</td>
				</tr>
			</table>
		</div>
	</div>
	<div id="MainArea">
		<table cellspacing="0" cellpadding="0" class="TableStyle">
			<!-- 表头-->
			<thead>
				<tr align=center valign=middle id=TableTitle>
					<td width="100">商品名称</td>
					<td width="100">商品单价</td>
					<td width="100">数量</td>
					<td width="100">相关操作</td>
				</tr>
			</thead>
			<!--显示数据列表-->
			<tbody id="TableData" class="dataContainer" datakey="userList">
				<s:iterator value="orderItems">
					<tr align="center" valign="middle" class="TableDetail1 template">
						<td><s:property value="goods.name" /></td>
						<td><s:property value="goods.price" /></td>
						<td><input id="edit<s:property value="goods.id"/>"
							name="<s:property value="goods.id"/>" type="text" class="editnum" />
							<div class="shownum"
								style="width: 80px;height: 15px; border:thin; border-style:dotted;"
								id="<s:property value="goods.id"/>">
								<s:property value="number" />
							</div> <label id="err<s:property value="goods.id"/>" class="err">
						</label></td>
						<td><a href="#"
							onclick="todelItem('<s:property value="goods.id"/>');">删除此项</a></td>
					</tr>
				</s:iterator>

			</tbody>

		</table>

		<!-- 其他功能超链接 -->
		<div id="TableTail">
			<div id="TableTail_inside">
				<button onclick="toSave();">
					<s:if test="dealType == 1">保存上架单</s:if>
					<s:if test="dealType == 2">保存下架单</s:if>
					<s:if test="dealType == 3">保存进货单</s:if>
					<s:if test="dealType == 4">保存退货单</s:if>
				</button>
				<button onclick="toClean();">
					<s:if test="dealType == 1">清除上架单</s:if>
					<s:if test="dealType == 2">清除下架单</s:if>
					<s:if test="dealType == 3">清除进货单</s:if>
					<s:if test="dealType == 4">清除退货单</s:if>
				</button>
				<button onclick="javascript:history.go(-1);">继续选择</button>
			</div>
		</div>
	</div>
</body>
</html>
